package com.mdhw.mili.service.impl;

import com.mdhw.mili.service.MiliProjectService;
import com.mdhw.mili.service.MiliTokenService;
import com.mdhw.utils.OkHttpUtil;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MiliProjectServiceImpl implements MiliProjectService {


    @Autowired
    private MiliTokenService miliTokenService;

    private String getProjectUrl = "http://testcloud.aurine.cn:28088/api/project";

    @Override
    public String getProject() {
        String token = this.miliTokenService.buildMiliToken();

        Map<String,String> headers = new HashMap<>();
        headers.put("Authorization", token);
        headers.put("PROJECT_ID", "6ae02faa71b84fe0be48f27fb69240e0");
        OkHttpUtil okHttpUtil = OkHttpUtil.getInstance();
        try {
            Response response = okHttpUtil.postDataWithBodyWithHeader(getProjectUrl, new HashMap<>(), headers);
            return response.body().string();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
